package vn.bus.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import vn.bus.dto.TimetableDTO;;

public class TimetableDAO {

	public ArrayList<TimetableDTO> getAllTimetables(Connection connection) throws Exception
	{
		ArrayList<TimetableDTO> allTimetables = new ArrayList<TimetableDTO>();
		try
		{
			PreparedStatement ps = connection.prepareStatement("SELECT * FROM timetable");
			ResultSet rs = ps.executeQuery();
			while(rs.next())
			{
				TimetableDTO Timetable = new TimetableDTO();
				Timetable.setArrival(rs.getInt("arrival"));
				Timetable.setConnection(rs.getInt("connection"));
				Timetable.setDeparture(rs.getInt("departure"));
				allTimetables.add(Timetable);
			}
			return allTimetables;
		}
		catch(Exception e)
		{
			throw e;
		}
	}
}
